<template>
	<view>
		<view style="height: 100vh;" class="padding bg-white">
			<view class="margin text-center">
				<template v-if="loading">
					<view>充值中，请稍候...</view>
				</template>
				<template v-else>
					<view v-if="bres">
						<view class="cuIcon-roundcheckfill text-green" style="font-size: 80upx;"></view>
						<view class="text-green margin" style="font-size:30upx">充值成功</view>
						<view>
							{{ 1 == payInfo.type ? '我们客服会第一时间联系您' : '感谢您的充值' }}
						</view>
					</view>
					<view v-else>
						<view class="cuIcon-roundclosefill text-red" style="font-size: 80upx;"></view>
						<view class="text-red margin">充值失败</view>
					</view>
				</template>
				<view>
					<button class="cu-btn margin-top-xl block lg" @tap="navTo">积分记录</button>
					<button class="cu-btn margin-top-xl block lg" @tap="BackPage">个人中心</button>
					<button class="cu-btn margin-top-xl block lg" @tap="home">返回首页</button>
				</view>
			</view>
			<view class="text-center margin-top">
				<view style="font-size:36upx">遇到问题？请联系客服</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bres: true,
				loading: true,
				payInfo: {
					type: 1
				},
				no: null
			};
		},
		onLoad(option) {
			if (option.no) {
				let _this = this;
				uni.showModal({
					showCancel: false,
				    content: '充值中，请稍候...',
				    success: function (res) {
				        if (res.confirm) {
				            _this.getPayRes(option.no);
				        } 
				    }
				});
			}
		},
		onShow() {
			//充值查询
			/*
			if (this.no) {
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				setTimeout(()=>{
					uni.hideLoading();
					this.getPayRes(this.no);
				}, 2000)
			}
			*/
		},
		methods: {
			home(){
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			navTo() {
				uni.navigateTo({
					url: '/pages/user/record'
				});
			},
			BackPage() {
				uni.switchTab({
					url: '/pages/user/user'
				});
			},
			getPayRes(out_trade_no) {
				let _this = this;
				this.baseRequest('api/driver/recharge/payres', 'POST', {
					out_trade_no
				}, function(res){
					uni.hideLoading();
					_this.payInfo = res;
					_this.bres = true;
					_this.loading = false;
				}, function(){
					uni.hideLoading();
					_this.bres = false;
					_this.loading = false;
				});
			},
		}
	}
</script>